package cn.edu.scau.dao;

import cn.edu.scau.entity.Manager;
import cn.edu.scau.entity.Medicationrecord;
import cn.edu.scau.entity.MedicationrecordShow;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
@CacheNamespace
public interface MedicationrecordMapper {
    @Delete({
        "delete from medicationrecord",
        "where medicationRecordID = #{medicationrecordid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer medicationrecordid);

    @Insert({
        "insert into medicationrecord (medicationRecordID, customerID, ",
        "medicationRecordDrugName, medicationRecordDosage, ",
        "medicationRecordMethod, medicationRecordShipper, ",
        "medicationRecordDispenser)",
        "values (#{medicationrecordid,jdbcType=INTEGER}, #{customerid,jdbcType=INTEGER}, ",
        "#{medicationrecorddrugname,jdbcType=VARCHAR}, #{medicationrecorddosage,jdbcType=VARCHAR}, ",
        "#{medicationrecordmethod,jdbcType=VARCHAR}, #{medicationrecordshipper,jdbcType=VARCHAR}, ",
        "#{medicationrecorddispenser,jdbcType=VARCHAR})"
    })
    @Options(useGeneratedKeys = true,keyColumn = "medicationRecordID",keyProperty = "medicationrecordid")
    int insert(Medicationrecord record);

    @InsertProvider(type=MedicationrecordSqlProvider.class, method="insertSelective")
    int insertSelective(Medicationrecord record);

    @Select({
        "select",
        "medicationRecordID, customerID, medicationRecordDrugName, medicationRecordDosage, ",
        "medicationRecordMethod, medicationRecordShipper, medicationRecordDispenser",
        "from medicationrecord",
        "where medicationRecordID = #{medicationrecordid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="medicationRecordID", property="medicationrecordid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER),
        @Result(column="medicationRecordDrugName", property="medicationrecorddrugname", jdbcType=JdbcType.VARCHAR),
        @Result(column="medicationRecordDosage", property="medicationrecorddosage", jdbcType=JdbcType.VARCHAR),
        @Result(column="medicationRecordMethod", property="medicationrecordmethod", jdbcType=JdbcType.VARCHAR),
        @Result(column="medicationRecordShipper", property="medicationrecordshipper", jdbcType=JdbcType.VARCHAR),
        @Result(column="medicationRecordDispenser", property="medicationrecorddispenser", jdbcType=JdbcType.VARCHAR)
    })
    Medicationrecord selectByPrimaryKey(Integer medicationrecordid);
    /**
     * 根据记录编号，客户编号模糊查询
     * @param medicationRecordID,customerID
     * @return 返回用药记录对象
     */
    @SelectProvider(type = MedicationrecordSqlProvider.class,method = "findByMIdCId")
    List<MedicationrecordShow> findByMIdCId(Integer medicationRecordID,Integer customerID);
    /**
     * 查找所有用药记录
     * @return
     */
    @Select({
            "select",
            "medicationRecordID, customerName, medicationRecordDrugName, medicationRecordDosage, ",
            "medicationRecordMethod, medicationRecordShipper, medicationRecordDispenser",
            "from customer c ,medicationrecord m",
            "where c.customerID=m.customerID"
    })
    List<MedicationrecordShow> selectAll();
    @UpdateProvider(type=MedicationrecordSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Medicationrecord record);

    @Update({
        "update medicationrecord",
        "set customerID = #{customerid,jdbcType=INTEGER},",
          "medicationRecordDrugName = #{medicationrecorddrugname,jdbcType=VARCHAR},",
          "medicationRecordDosage = #{medicationrecorddosage,jdbcType=VARCHAR},",
          "medicationRecordMethod = #{medicationrecordmethod,jdbcType=VARCHAR},",
          "medicationRecordShipper = #{medicationrecordshipper,jdbcType=VARCHAR},",
          "medicationRecordDispenser = #{medicationrecorddispenser,jdbcType=VARCHAR}",
        "where medicationRecordID = #{medicationrecordid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Medicationrecord record);
}